module.exports = option => {
    const jwt = require("jsonwebtoken");
    const assert = require("http-assert");
    return async (req, res, next) => {
        try {
            const token = String(req.headers.authorization || "").split(" ")[1]
            // console.log(token);
            assert(token, 401, "无效的token")
            const jwt = require("jsonwebtoken");
            const { _id } = jwt.verify(token, req.app.get("secret"))
            // console.log(_id);
            assert(_id, 401, "无效的token")
            const user = await require("./../models/AdminUser").findById(_id)
            // console.log(user);
            assert(user, 401, "身份验证错误!")
            req._id = _id;
        } catch (err) { next(err) }
        await next()
    }
}